package com.elong.businesstravel.protocol.city;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONObject;

import com.elong.businesstravel.entitys.CityPoi;
import com.elong.businesstravel.entitys.Poi;
import com.elong.businesstravel.protocol.baseresponse.BaseELongJsonHttpResponse;

public class GetPoiByCityResponse extends BaseELongJsonHttpResponse {
	
	public List<CityPoi> mCityPois = new ArrayList<CityPoi>();
	public String mResponseString;
	
	@Override
	public void onSuccess(int statusCode, Header[] headers,
			JSONObject mainJsonObject) throws Throwable {
		
		mResponseString = mainJsonObject.toString();
		
		JSONObject responseJsonObject = mainJsonObject.getJSONObject("response");
		
		List<String> tindexList = new ArrayList<String>();
		JSONArray tindexArray = responseJsonObject.getJSONArray("tindex");
		for (int i = 0; i < tindexArray.length(); i++) {
			tindexList.add(tindexArray.getString(i));
		}
		
		for (int i = 0; i < tindexList.size(); i++) {
			CityPoi cityPoi = new CityPoi();
			cityPoi.name = tindexList.get(i);
			JSONArray poiArray = responseJsonObject.getJSONArray(cityPoi.name);
			for (int j = 0; j < poiArray.length(); j++) {
				Poi poi = new Poi();
				JSONObject itemPoiObject = poiArray.getJSONObject(j);
				poi.googlelat = itemPoiObject.optDouble("googlelat",0);
				poi.line = itemPoiObject.optString("line","");
				poi.poiid = itemPoiObject.optString("poiid","");
				poi.precount = itemPoiObject.optString("precount","");
				poi.googlelng = itemPoiObject.optDouble("googlelng",0);
				poi.name = itemPoiObject.optString("name","");
				poi.cityid = itemPoiObject.optString("cityid","");
				poi.id = itemPoiObject.optString("id", "");
				poi.districtsid = itemPoiObject.optString("districtsid", "");
				poi.districtsname = itemPoiObject.optString("districtsname", "");
				poi.sorts = itemPoiObject.optString("sorts", "");
				poi.bussinename = itemPoiObject.optString("bussinename", "");
				poi.bussinesid = itemPoiObject.optString("bussinesid", "");
				cityPoi.pois.add(poi);
			}
			mCityPois.add(cityPoi);
		}
		
		
	}

}
